package org.redis.cluster.event;

import org.redis.cluster.transport.event.SessionClosedEvent;
import org.redis.cluster.transport.event.SessionCreatedEvent;
import org.redis.cluster.transport.session.Session;

public abstract class AbstractSessionEventListener implements EventListener<Event> {

	@Override
	public void onEvent(Event event) {
		if(event instanceof SessionCreatedEvent) {
			doSessionCreatedProcess(((SessionCreatedEvent) event).getSession());
		}
		else if(event instanceof SessionClosedEvent) {
			doSessionClosedProcess(((SessionClosedEvent) event).getSession());
		}
	}

	@Override
	public boolean isSupport(Event event) {
		return (event instanceof SessionCreatedEvent) || (event instanceof SessionClosedEvent);
	}
	
	protected abstract void doSessionCreatedProcess(Session session);

	protected abstract void doSessionClosedProcess(Session session);

}